<template>
	<div class="add-borrow-record">
		<div>
			<label>{{$t('route.Device')}}</label>
			<div></div>
			<button><img /><label>{{$t('route.Add_borrowing_record')}}</label></button>
		</div>
		<div>
			<div class="div-1">
				<label class="title">{{$t('route.Head_Model')}}:</label>
				<el-input class="content" v-model="form.noseCode" />
				<label class="title">{{$t('route.kind')}}:</label>
				<el-select class="content" v-model="form.kind" :placeholder="$t('route.Please_select_the_type')">
					<el-option v-for="item in kindList" :key="item" :label="item" :value="item" />
				</el-select>
			</div>

			<div class="div-1">
				<label class="title">{{$t('route.borrower')}}:</label>
				<el-input class="content" v-model="form.borrow" />
				<label class="title">{{$t('route.contact_number')}}:</label>
				<el-input class="content" v-model="form.borrowMobile" />
			</div>

			<div class="div-1">
				<label class="title">{{$t('route.Lender')}}:</label>
				<el-input class="content" v-model="form.borrowed" />
				<label class="title">{{$t('route.contact_number')}}:</label>
				<el-input class="content" v-model="form.borrowedMobile" />
			</div>

			<div class="div-1">
				<label class="title">{{$t('route.Borrowing_time')}}:</label>
				<el-date-picker style="margin-left: 20px;width: 250px;" v-model="form.borrowDate" type="date"
					:placeholder="$t('route.Please_select_the_type')" />
				<label class="title">{{$t('route.Agreed_Return_Date')}}:</label>
				<el-date-picker style="margin-left: 20px;width: 250px;" v-model="form.agreedReturnDate" type="date"
					:placeholder="$t('route.Please_select_the_type')" />
			</div>
			<div v-if="false" class="div-1">
				<label class="title">{{$t('route.Return_to_Recipient')}}:</label>
				<el-input class="content" v-model="form.receiver" />
				<label class="title">{{$t('route.contact_number')}}:</label>
				<el-input class="content" v-model="form.receiverMobile" />
			</div>

			<div class="div-1">
				<el-button type="primary" @click='addClick'>{{$t('route.Add')}}</el-button>
			</div>

		</div>


	</div>
</template>

<script>
	import http from "../../js/http/http.js";
	import api from "../../js/http/api.js";
	import CommonUtils from "../../js/common/common-utils.js";
	import Constant from '../../js/common/constant.js'
	import i18n from '../../i18n/index';
	export default {
		data() {
			return {
				form: {
					noseCode: null,
					borrow: null,
					borrowMobile: null,
					borrowed: null,
					borrowedMobile: null,
					borrowDate: new Date(),
					agreedReturnDate: null,
					receiver: null,
					receiverMobile: null,
					kind: null
				},
				kindList: Constant.DEVICE_KIND
			};
		},
		methods: {
			addClick() {
				if (CommonUtils.isEmpty(this.form.noseCode)) {
					this.$message.error(i18n.global.t('route.The_nose_number_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.kind)) {
					this.$message.error(i18n.global.t('route.Category_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.borrow)) {
					this.$message.error(i18n.global.t('route.The_borrower_company_cannot_be_blank1'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.borrowMobile)) {
					this.$message.error(i18n.global.t('route.Contact_number_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.borrowed)) {
					this.$message.error(i18n.global.t('route.The_borrower_company_cannot_be_blank2'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.borrowedMobile)) {
					this.$message.error(i18n.global.t('route.Contact_number_cannot_be_empty'));
					return;
				}
				if (CommonUtils.isEmpty(this.form.agreedReturnDate)) {
					this.$message.error(i18n.global.t('route.The_agreed_return_date_cannot_be_blank'));
					return;
				}

				this.addBorrowRecord();
			},
			addBorrowRecord() {
				http.post(api.ADD_BORROW_RECORD, {
					adminId: this.$store.state.user.id,
					noseCode: this.form.noseCode,
					borrow: this.form.borrow,
					borrowMobile: this.form.borrowMobile,
					borrowed: this.form.borrowed,
					borrowedMobile: this.form.borrowedMobile,
					borrowDate: this.form.borrowDate.format('yyyy-MM-dd'),
					agreedReturnDate: this.form.agreedReturnDate.format('yyyy-MM-dd'),
					receiver: this.form.receiver,
					receiverMobile: this.form.receiverMobile,
					kind: this.form.kind,
				}, data => {
					this.$message.success(i18n.global.t('route.Successfully_added'));

				})

			}
		},
		created() {

		}
	};
</script>
<style lang="scss" scoped>
	.add-borrow-record {
		color: #444444;
		font-size: 18px;
		padding-right: 20px;
		height: calc(100vh - 100px);
		// overflow: scroll;
		scrollbar-width: none;
		/* firefox */
		-ms-overflow-style: none;
		/* IE 10+ */
		overflow-x: hidden;
		overflow-y: auto;


		>div:nth-of-type(1) {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			>label:nth-of-type(1) {
				font-weight: 600;
			}

			>div:nth-of-type(1) {
				width: 1px;
				background-color: #cccccc;
				height: 15px;
				margin: 0px 20px;
			}

			>button:nth-of-type(1) {
				background-image: url(../../assets/img/customer-1.png);
				background-repeat: no-repeat;
				background-size: 100% 100%;
				padding: 5px 10px;
				border: 0px;
				display: flex;
				color: #ffffff;
				flex-direction: row;
				align-items: center;
				font-weight: 800;

				>img {
					margin-right: 7px;
					width: 15px;
					height: 15px;
					content: url(../../assets/img/customer-2.png);
				}

			}
		}

		>div:nth-of-type(2) {
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			margin-top: 20px;
			background-color: #ffffff;
			padding: 20px;
			border-radius: 5px;

			.div-1 {
				display: flex;
				flex-direction: row;
				margin-top: 20px;
				align-items: center;

				.title {
					font-size: 15px;
					width: 120px;
					text-align: right;
				}

				.content {
					margin-left: 20px;
					width: 250px;
				}

				>button {
					margin-left: 140px;
					width: 250px;
				}

			}


		}

	}
</style>
